package com.buobao.bmall.service.impl;

import com.buobao.bmall.model.dao.UserMapper;
import com.buobao.bmall.model.pojo.User;
import com.buobao.bmall.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User selectUserById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public User selectUserByName(String username) {
        return userMapper.selectByName(username);
    }

    @Transactional
    @Override
    public Integer insertUser(User user) {
        return userMapper.insert(user);
    }

    @Transactional
    @Override
    public Integer updateByPrimaryKey(User user) {
        return userMapper.updateByPrimaryKey(user);
    }

    @Override
    public boolean checkAdmin(User user) {
        return "2".equals(user.getRole());
    }
}
